﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.ObjectBuilder;
using NetDon.OA.Interface.Common;
using NetDon.Utilities;

namespace NetDon.OA.Portal.Admin
{
    public partial class RouteInfoManagement : PageBase, IRouteInfoView
    {
        private RouteInfoPresenter _presenter;

        [CreateNew]
        public RouteInfoPresenter Presenter
        {
            set
            {
                _presenter = value;
                _presenter.View = this;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _presenter.OnViewInitialized();
            }
            _presenter.OnViewLoaded();
        }

        protected void gridItem_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var btnModify = e.Row.FindControl("btnModify") as ImageButton;
                if (btnModify != null)
                {
                    btnModify.OnClientClick = string.Format("OpenEditPage('{0}');return false;",
                                                              DataBinder.Eval(e.Row.DataItem, "Id"));
                }
            }
        }

        protected void gridItem_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "DeleteItem":
                    OnRemoveCurrency(new EventArgs<Guid>(e.CommandArgument.ToString().ToGuid()));
                    break;
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            OnRefereshCurrencies(EventArgs.Empty);
        }

        #region Implementation of ICurrencyView

        public void PopulateRoutes(IEnumerable<RouteData> currencies)
        {
            gridCurrency.DataSource = currencies;
            gridCurrency.DataBind();
        }

        public event EventHandler RefereshRoutes;

        protected virtual void OnRefereshCurrencies(EventArgs e)
        {
            if (RefereshRoutes != null)
            {
                RefereshRoutes(this, e);
            }
        }
        public event EventHandler<EventArgs<Guid>> RemoveRoute;

        protected virtual void OnRemoveCurrency(EventArgs<Guid> e)
        {
            if (RemoveRoute != null)
            {
                RemoveRoute(this, e);
            }
        }

        #endregion


 
    }
}